package com.example.concurrency.thread03;

/**
 * @description:
 * @program: demos
 * @author: dove
 * @date: 2020-12-03 23:54
 * Thread的构造函数：
 * Thread();
 * Thread(Runnable r);
 * Thread(Runnable r, String rName);
 * Thread(String name);
 * Thread(ThreadGroup g, Runnable r);
 *  如果不指定group，这里的group指的是谁呢？g = parent.getThreadGroup();也就是说，线程是被谁创建的，那么它的group就是谁
 *  以下的几个线程都是被main方法创建出来的，可以推知，线程的线程组就是main线程所在的线程组
 **/
public class ThreadConstruct01 {
    public static void main(String[] args) {
        // Thread()
        Thread thread = new Thread(){
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName());
            }
        };
        thread.start();

        // Thread(String name);
        Thread thread1 = new Thread("^thread1^"){
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName());
            }
        };
        thread1.start();

        // Thread(Runnable r)
        Thread thread2 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName());
            }
        });
//        Thread thread2 = new Thread(()-> System.out.println(Thread.currentThread().getName()));
        thread2.start();

        // Thread(Runnable r, String rName);
        Thread thread3 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName());
            }
        },"^thread3^");
//        Thread thread3 = new Thread(()-> System.out.println(Thread.currentThread().getName()),"^thread3^");
        thread3.start();

        // Thread(ThreadGroup g, Runnable r);
        Thread thread4 = new Thread(new ThreadGroup("testGroup"),()->{
            System.out.println(Thread.currentThread().getName());
            System.out.println(Thread.currentThread().getThreadGroup());
        });
        thread4.start();
    }
}
